package com.woniuxy.reader.controller;


import com.woniuxy.reader.entity.Editor;
import com.woniuxy.reader.service.AuthorService;
import com.woniuxy.reader.service.BookService;
import com.woniuxy.reader.service.EditorService;
import com.woniuxy.reader.service.ManagerService;
import com.woniuxy.reader.service.impl.ManagerServiceImpl;
import com.woniuxy.reader.vo.AuthorVO;
import com.woniuxy.reader.vo.UserVO;
import com.woniuxy.result.ResponseResult;
import com.woniuxy.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员控制器
 *
 * @author zh_o
 * @since 2020-10-09
 */
@RestController
@RequestMapping("/manager")
@Api(tags = "管理员接口")
public class ManagerController {

    @Autowired
    private EditorService editorService;

    @Autowired
    private BookService bookService;

    @Autowired
    private ManagerService managerService;

    @Autowired
    private AuthorService authorService;

    @RequestMapping("login")
    @ApiOperation("管理员/编辑 唯一登录")
    public Result login(String tel, String password) {
        return Result.success(managerService.login(tel, password));
    }

    /**
     * 用户列表
     *
     * @param vo
     * @return
     */
    @RequestMapping("user")
    @ApiOperation("查询用户列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名"),
            @ApiImplicitParam(name = "pageNum", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数"),
    })
    public Object listUsers(UserVO vo) {
        return ResponseResult.success(managerService.listUserAndSubscribe(vo));
    }

    /**
     * 作者列表
     *
     * @param vo
     * @return
     */
    @RequestMapping("author")
    @ApiOperation("查询作者列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "作者名 / 笔名 "),
            @ApiImplicitParam(name = "pageNum", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数"),
    })
    public Object listAuthors(AuthorVO vo) {
        return ResponseResult.success(managerService.listAuthorByBook(vo));
    }


    @GetMapping("allsigneditor")
    @ApiOperation("查询所有编辑手下签约的作者，作品数")
    public Result selectAllSignEditor() {
        return Result.success(editorService.selectAllSignEditor());
    }
    @GetMapping("alleditor")
    @ApiOperation("查询所有编辑")
    public Result selectAllEditor(){
        return Result.success(managerService.selectAllEditor());
    }

    @GetMapping("allauthor")
    @ApiOperation("查询所有作者")
    public Result selectAllAuthor(){
        return Result.success(managerService.selectAllAuthor());
    }

    @GetMapping("allbook")
    @ApiOperation("查询所有的作品数据，包括作品的状态、作品的字数、作品的连载状态等")
    public Result selectAllBook() {
        System.out.println("-------------------------------------!!!!");
        return Result.success(bookService.selectAllBook());
    }

    @PostMapping("{bookid}")
    @ApiOperation("管理员禁书(传入书籍id)")
    public Result updateBook(@PathVariable("bookid") int bookid) {
        System.out.println(bookid);
        bookService.updateBook(bookid);
        return Result.success("禁书成功");
    }

    @PostMapping("setboutique/{bookid}")
    @ApiOperation("管理员设置精品(传入书籍id)")
    public Result setBoutique(@PathVariable("bookid") int bookid) {
        bookService.setBoutique(bookid);
        return Result.success("设置精品成功");
    }

    @PostMapping("setnormal/{bookid}")
    @ApiOperation("管理员取消精品(传入书籍id)")
    public Result setNormal(@PathVariable("bookid") int bookid) {
        bookService.setnormal(bookid);
        return Result.success("取消精品成功");
    }

    @RequestMapping("add")
    @ApiOperation("新增责编")
    public Result insertEditor(String tel) {
        System.out.println("本次新增------------------------------->" + tel);
        return Result.success(editorService.insertEditor(tel));
    }

    @RequestMapping("managerselect")
    @ApiOperation("根据作者id查询所有书籍")
    public Result managerselect(String authorid){
        System.out.println("------------------------");
        System.out.println(authorid);
        return Result.success(bookService.managerselect(authorid));
    }

}

